package com.rocksea.checkservice;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;

/**
 * Created by Mrw on 2017/8/19.
 *
 */

class ServiceAdapter extends BaseAdapter
{
    private Context context;
    private ArrayList<ServiceInfo> mServiceInfos;

    public ServiceAdapter(Context context, ArrayList<ServiceInfo> mServices)
    {
        this.context = context;
        this.mServiceInfos = mServices;

    }

    @Override
    public int getCount() {
        return mServiceInfos.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }
    @Override
    public long getItemId(int position) {
        return 0;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        if (convertView==null)
            convertView = View.inflate(context,R.layout.item_service,null);
        TextView mNameTv = (TextView) convertView.findViewById(R.id.Name);
        TextView mIpTv = (TextView) convertView.findViewById(R.id.ip);
        mNameTv.setText(mServiceInfos.get(position).getRegionName());
        mIpTv.setText(String.format("%s:%s",mServiceInfos.get(position).getServerIp(),mServiceInfos.get(position).getDtuPort()));
        return convertView;
    }
}
